import 'dart:io';

import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/foundation.dart';
import 'package:permission_handler/permission_handler.dart';

mixin PPPagePermissionMixin {
  Future<bool> externalStorageIsGranted() async {
    if (Platform.isAndroid) {
      try {
        var info = await DeviceInfoPlugin().androidInfo;
        int androidVersion = info.version.sdkInt;
        if (androidVersion >= 30) {
          var isGranted =
              await Permission.manageExternalStorage.request().isGranted;
          if (!isGranted) {
            return false;
          }
        }
      } catch (e) {
        debugPrint("externalStorageIsGranted error: $e");
      }
    }
    return true;
  }
}
